package com.zhao.Util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhao.pojo.Wallet;
import com.zhao.service.WalletService;
import com.zhao.service.serviceImpl.WalletServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

public class WalletUtil {

    public static Wallet ComputeIntegral(Wallet wallet,int addIntegral){

        int newIntegral =Integer.parseInt(wallet.getPrice())+addIntegral;
        wallet.setPrice(newIntegral+"");
        String newGrade = ComputeGrade(newIntegral);
        if (!newGrade.equals(wallet.getGrade())){
            wallet.setGrade(newGrade);
        }
        System.out.println("====>"+wallet.toString());
        return wallet;
    }
    private static String ComputeGrade(int integral){
        String grade="L";
       if (integral<100){
           grade=1+grade;
       }else if (integral < 400){
           grade=2+grade;
       }else if (integral < 800){
           grade=3+grade;
       }else if (integral < 1600){
           grade=4+grade;
       }else if (integral < 4500){
           grade=5+grade;
       }else if (integral < 9000){
           grade=6+grade;
       }else if (integral < 25000){
           grade=7+grade;
       }else if (integral < 50000){
           grade=8+grade;
       }else if (integral < 100000){
           grade=9+grade;
       }else if (integral < 200000){
           grade=10+grade;
       }else if (integral < 300000){
           grade=11+grade;
       }else if (integral < 500000){
           grade=12+grade;
       }else if (integral < 800000){
           grade=13+grade;
       }else if (integral < 1000000){
           grade=14+grade;
       }
        return grade;
    }

}
